package main

import (

)

const (
	BakMongodConfFileName = "mongod.conf.repl"
)

const (
	TcmallocAggressiveMemoryDecommit = "tcmallocAggressiveMemoryDecommit"
	AsioConnections                  = "asioConnections"
)

type Proxy2Config struct {
	LogLevel     string       `yaml:"logLevel"`
	LogPath      string       `yaml:"logPath"`
	MetaUrl      string       `yaml:"metaUrl"`
	PidFile      string       `yaml:"pidFile"`
	Net          Net          `yaml:"net,omitempty"`
	Mongo        MongoConf    `yaml:"mongo"`
	Proxy        ProxyConf    `yaml:"proxy"`
	Asio         AsioConf     `yaml:"asio"`
	SetParameter SetParameter `yaml:"setParameter"`
}

type MongosConfig struct {
	SystemLog         SystemLog    `yaml:"systemLog"`
	ProcessManagement Process      `yaml:"processManagement"`
	Net               Net          `yaml:"net"`
	Security          Security     `yaml:"security"`
	Sharding          Sharding     `yaml:"sharding"`
	ClusterName       string       `yaml:"clusterName,omitempty"`
	MetaUrl           string       `yaml:"metaUrl,omitempty"`
	SetParameter      SetParameter `yaml:"setParameter"`
}

type MongoConf struct {
	ClusterName string `yaml:"clusterName"`
}

type ProxyConf struct {
	EnableSharding            int `yaml:"enableSharding"`
	Port                      int `yaml:"port"`
	MessageTimeout            int `yaml:"messageTimeout"`
	ClientIdleTimeout         int `yaml:"clientIdleTimeout"`
	ServerIdleTimeout         int `yaml:"serverIdleTimeout"`
	GetLastErrorTimeout       int `yaml:"getLastErrorTimeout"`
	ServerClosePoolSize       int `yaml:"serverClosePoolSize"`
	MaxPerClientConnections   int `yaml:"maxPerClientConnections"`
	MaxConnections            int `yaml:"maxConnections"`
	GlobalMaxQueueSizePerHost int `yaml:"globalMaxQueueSizePerHost,omitempty"`
	ShardMaxQueueSizePerHost  int `yaml:"shardMaxQueueSizePerHost,omitempty"`
}

type AsioConf struct {
	WorkerNum                    int `yaml:"workerNum"`
	MinConnPerHostPerWorker      int `yaml:"minConnPerHostPerWorker"`
	MaxConnPerHostPerWorker      int `yaml:"maxConnPerHostPerWorker"`
	MaxQueueSizePerHostPerWorker int `yaml:"maxQueueSizePerHostPerWorker,omitempty"`
}

type MongodConfigWT struct {
	SystemLog         SystemLog    `yaml:"systemLog"`
	ProcessManagement Process      `yaml:"processManagement"`
	Net               Net          `yaml:"net"`
	SetParameter      SetParameter `yaml:"setParameter"`
	Security          Security     `yaml:"security"`
	Storage           StorageWT    `yaml:"storage"`
	Replication       Replication  `yaml:"replication"`
	Sharding          Sharding     `yaml:"sharding"`
}

type SystemLog struct {
	Verbosity       int    `yaml:"verbosity"`
	Path            string `yaml:"path"`
	LogAppend       bool   `yaml:"logAppend"`
	LogRotate       string `yaml:"logRotate"`
	Destination     string `yaml:"destination"`
	TimeStampFormat string `yaml:"timeStampFormat"`
}

type SetParameter struct {
	TtlMonitorEnabled                   bool   `yaml:"ttlMonitorEnabled,omitempty"`
	TtlMonitorSleepSecs                 int    `yaml:"ttlMonitorSleepSecs,omitempty"`
	TtlDeleteBatch                      int    `yaml:"ttlDeleteBatch,omitempty"`
	DisabledSecureAllocatorDomains      string `yaml:"disabledSecureAllocatorDomains,omitempty"`
	TcmallocAggressiveMemoryDecommit    int    `yaml:"tcmallocAggressiveMemoryDecommit,omitempty"`
	TcmallocMaxTotalThreadCacheBytes    int    `yaml:"tcmallocMaxTotalThreadCacheBytes,omitempty"`
	ShardingTaskExecutorPoolMaxSize     int    `yaml:"ShardingTaskExecutorPoolMaxSize,omitempty"`
	ShardingTaskExecutorPoolMinSize     int    `yaml:"ShardingTaskExecutorPoolMinSize,omitempty"`
	TaskExecutorPoolSize                int    `yaml:"taskExecutorPoolSize,omitempty"`
	ConnPoolMaxShardedConnsPerHost      int    `yaml:"connPoolMaxShardedConnsPerHost,omitempty"`
	ConnPoolMaxConnsPerHost             int    `yaml:"connPoolMaxConnsPerHost,omitempty"`
	RequestOverloadQueueSize            int    `yaml:"requestOverloadQueueSize,omitempty"`            // new in CMongo40
	ConnPoolMaxInUseConnsPerHost        int    `yaml:"connPoolMaxInUseConnsPerHost,omitempty"`        // 内部连接池最大可用连接数
	ConnPoolMaxShardedInUseConnsPerHost int    `yaml:"connPoolMaxShardedInUseConnsPerHost,omitempty"` // Shard连接池最大可用连接数
}

type Process struct {
	Fork        bool   `yaml:"fork"`
	PidFilePath string `yaml:"pidFilePath"`
}

type Net struct {
	Port                   int  `yaml:"port,omitempty"`
	BindIpAll              bool `yaml:"bindIpAll,omitempty"`
	MaxIncomingConnections int  `yaml:"maxIncomingConnections,omitempty"`
	Ipv6                   bool `yaml:"ipv6,omitempty"`
}

type Security struct {
	KeyFile string `yaml:"keyFile"`
}

type StorageWT struct {
	DbPath         string     `yaml:"dbPath"`
	DirectoryPerDB bool       `yaml:"directoryPerDB"`
	SyncPeriodSecs int        `yaml:"syncPeriodSecs"`
	WiredTiger     WiredTiger `yaml:"wiredTiger"`
}

type WiredTiger struct {
	EngineConfig   EngineConfig   `yaml:"engineConfig"`
	EvictionConfig EvictionConfig `yaml:"evictionConfig,omitempty"` //only used in CMongo3.2 high versions
}

type EngineConfig struct {
	CacheSizeGB float32 `yaml:"cacheSizeGB"`
}

type EvictionConfig struct {
	EvictionDirtyTarget      int `yaml:"evictionDirtyTarget,omitempty"`
	EvictionDirtyTrigger     int `yaml:"evictionDirtyTrigger,omitempty"`
	EvictionTarget           int `yaml:"evictionTarget,omitempty"`
	EvictionTrigger          int `yaml:"evictionTrigger,omitempty"`
	EvictionCheckPointTarget int `yaml:"evictionCheckPointTarget,omitempty"`
	EvictionThreadsMax       int `yaml:"evictionThreadsMax,omitempty"`
	EvictionThreadsMin       int `yaml:"evictionThreadsMin,omitempty"`
}

type Replication struct {
	OplogSizeMB int64  `yaml:"oplogSizeMB,omitempty"`
	ReplSetName string `yaml:"replSetName,omitempty"`
}

type Sharding struct {
	ClusterRole        string `yaml:"clusterRole,omitempty"`        // in mongod
	ArchiveMovedChunks bool   `yaml:"archiveMovedChunks,omitempty"` // in mongod
	ConfigDB           string `yaml:"configDB,omitempty"`           // in mongos
}

type MongodConfigRocks struct {
	SystemLog                 SystemLog    `yaml:"systemLog"`
	ProcessManagement         Process      `yaml:"processManagement"`
	Security                  Security     `yaml:"security"`
	Net                       Net          `yaml:"net"`
	Storage                   StorageRocks `yaml:"storage"`
	ConfigString              string       `yaml:"storage.rocksdb.configString"`
	CacheSizeGB               float32      `yaml:"storage.rocksdb.cacheSizeGB"`
	Counters                  bool         `yaml:"storage.rocksdb.counters"`
	CacheIndexAndFilterBlocks bool         `yaml:"storage.rocksdb.cacheIndexAndFilterBlocks"`
	Replication               Replication  `yaml:"replication"`
	Sharding                  Sharding     `yaml:"sharding"`
	SetParameter              SetParameter `yaml:"setParameter"`
}

type StorageRocks struct {
	DbPath         string `yaml:"dbPath"`
	SyncPeriodSecs int    `yaml:"syncPeriodSecs"`
	Engine         string `yaml:"engine"`
}

